import 'package:flutter/material.dart';
import 'package:flutter_learning/page_lifecycle/base_page_lifecycle_state.dart';

class LifecycleHomeView extends StatefulWidget {
  const LifecycleHomeView({super.key});

  @override
  State<LifecycleHomeView> createState() => _LifecycleHomeViewState();
}

class _LifecycleHomeViewState extends BasePageLifecycleState<LifecycleHomeView> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("主页"),
      ),
      body: Container(
        color: Colors.cyan,
      ),
      floatingActionButton: GestureDetector(
          onTap: () {
            Navigator.push(context, MaterialPageRoute(builder: (_) => LifecyclePage2()));
          },
          child: Container(
            height: 50,
            width: 50,
            child: Text("跳转"),
          )),
    );
  }

  @override
  void pageDidLoad() {
    super.pageDidLoad();
  }

  @override
  void pageDidAppear(bool isPush) {
    super.pageDidAppear(isPush);
  }

  @override
  void pageDidDisappear(bool isPop) {
    super.pageDidDisappear(isPop);
  }
}

class LifecyclePage2 extends StatefulWidget {
  const LifecyclePage2({super.key});

  @override
  State<LifecyclePage2> createState() => _LifecyclePage2State();
}

class _LifecyclePage2State extends BasePageLifecycleState<LifecyclePage2> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("页面1"),
      ),
      body: GestureDetector(
        onTap: () {
          Navigator.push(context, MaterialPageRoute(builder: (_) => LifeCyclePage3()));
        },
        child: Container(
          color: Colors.blue,
          alignment: Alignment.center,
          child: Text("点击跳转"),
        ),
      ),
      floatingActionButton: GestureDetector(
          onTap: () {
            Navigator.pop(context);
          },
          child: Container(
            height: 50,
            width: 50,
            child: Text("返回"),
          )),
    );
  }

  @override
  void pageDidLoad() {
    super.pageDidLoad();
  }

  @override
  void pageDidAppear(bool isPush) {
    super.pageDidAppear(isPush);
  }

  @override
  void pageDidDisappear(bool isPop) {
    super.pageDidDisappear(isPop);
  }

  @override
  void appEnterBackground() {
    // TODO: implement appEnterBackground
    super.appEnterBackground();
  }

  @override
  void appEnterForeground() {
    // TODO: implement appEnterForeground
    super.appEnterForeground();
  }
}

class LifeCyclePage3 extends StatefulWidget {
  const LifeCyclePage3({super.key});

  @override
  State<LifeCyclePage3> createState() => _LifeCyclePage3State();
}

class _LifeCyclePage3State extends BasePageLifecycleState<LifeCyclePage3> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("页面2"),
      ),
      body: Container(
        color: Colors.orange,
      ),
      floatingActionButton: GestureDetector(
          onTap: () {
            Navigator.pop(context);
          },
          child: Container(
            height: 50,
            width: 50,
            child: Text("返回"),
          )),
    );
  }

  @override
  void pageDidLoad() {
    super.pageDidLoad();
  }

  @override
  void pageDidAppear(bool isPush) {
    super.pageDidAppear(isPush);
  }

  @override
  void pageDidDisappear(bool isPop) {
    super.pageDidDisappear(isPop);
  }
}
